using System.Reflection;
using B.S.ReportEvent.ApiNew.Extensions;
using B.S.ReportEvent.Infrastructure;
using ServiceManagement.Consul;



var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(x =>
{
    string xml = AppDomain.CurrentDomain.BaseDirectory + "B.S.ReportEvent.Api.xml";
    x.IncludeXmlComments(xml, true);
});

//注入数据上下文类
builder.Services.AddDbContextService<BaseDataDbContext>(builder.Configuration.GetConnectionString("con"), true);

//注入中介者
builder.Services.AddMediatR(o => o.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));

//注入 jwt
builder.Services.AddJwt(builder);

//注入服务
builder.Services.AddServices();

//注入 Consul
builder.Configuration.Register();



builder.Services.AddHttpClient();


var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

//启用路由功能
app.UseRouting();

//极短api
app.MapGet("/api/healthcheck", () => "ok");

//跨域
app.UseCors(x => x.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());

//启用认证
app.UseAuthentication();

app.UseAuthorization();



app.MapControllers();

app.Run();